package com.wujie.hello.spring.cloud.alibaba.nacos.oauth.authorization.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.security.Principal;

/**
 * @author wujie
 * @version 1.0.0:
 * @title UserController
 * @Description TODO
 * @dateTime 2020/9/9 13:00
 * @Copyright 2020-2021
 */
@RestController
@Slf4j
public class UserController {

    @GetMapping("/user")
    public Object userInfo(Principal user, Authentication authentication) {
        log.info("user:{}",user);
        log.info("auth:{}", authentication);
        return  user;
    }
    /**
     * 认证页面
     * @return ModelAndView
     */
    @GetMapping("/login")
    public ModelAndView require() {
        log.info("---认证页面---");
        return new ModelAndView("ftl/login");
    }
    @PreAuthorize("hasAuthority('ROLE_USER')")
    @GetMapping("/test/need_admin")
    public @ResponseBody String admin() {
        return "need_admin";
    }

}
